/**
 *
 */
package com.angel.mocks.io.rowProcessorCommands;

import com.angel.common.helpers.StringHelper;
import com.angel.data.generator.annotations.Inject;
import com.angel.io.exceptions.InvalidRowDataException;
import com.angel.io.parameters.ParametersService;
import com.angel.io.processors.commands.imports.ImportRowProcessorCommand;
import com.angel.io.type.rows.ImportRowFile;
import com.angel.io.type.rows.impl.HeaderRowFile;
import com.angel.mocks.daos.AddressDAO;
import com.angel.mocks.io.Hotel;

/**
 * @author William
 *
 */
public class HotelRowProcessorCommand implements ImportRowProcessorCommand{

    public static final String OFICIAL_DESCRIPTION_COLUMN = "oficialDescription";
	public static final String NAME_COLUMN = "name";
	public static final String URL_ADDRESS_COLUMN = "urlAddress";
	public static final String EMAIL_COLUMN = "email";
	public static final String ADDRESS_COLUMN = "address";
	public static final String TELEPHONE_COLUMN = "telephone";

	@Inject(beanName = "addressDAO")
	protected AddressDAO addressDAO;

	@Inject
	protected AddressDAO addressesDAO;

    public void checkRowData(ImportRowFile importRowFile, HeaderRowFile headerRowFile) throws InvalidRowDataException {
        String name = importRowFile.getStringValue(headerRowFile.getColumnPosition(NAME_COLUMN));
		String urlAddress = importRowFile.getStringValue(headerRowFile.getColumnPosition(URL_ADDRESS_COLUMN));
		String oficialDescription = importRowFile.getStringValue(headerRowFile.getColumnPosition(OFICIAL_DESCRIPTION_COLUMN));
		String email = importRowFile.getStringValue(headerRowFile.getColumnPosition(EMAIL_COLUMN));
		String address = importRowFile.getStringValue(headerRowFile.getColumnPosition(ADDRESS_COLUMN));
		String telephone = importRowFile.getStringValue(headerRowFile.getColumnPosition(TELEPHONE_COLUMN));
		boolean areAllNotEmpty = StringHelper.areAllNotEmpty(name, urlAddress, oficialDescription, email, address, telephone);
		if(!areAllNotEmpty){
			throw new InvalidRowDataException("Some row data are NULL - " +
					"Name: [" + name + "] - " +
					"URL Address: [" + urlAddress  + "] - " +
					"Email: [" + email  + "] - " +
					"Address: [" + address  + "] - " +
					"Telephone: [" + telephone  + "] - " +
					"Oficial Description: [" + oficialDescription + "] - ");
		}
    }

	@SuppressWarnings("unchecked")
	public <T> T processRow(ImportRowFile importRowFile, HeaderRowFile headerRowFile, ParametersService parametersService) {
        String urlAddress = importRowFile.getStringValue(headerRowFile.getColumnPosition(URL_ADDRESS_COLUMN));
		String name = importRowFile.getStringValue(headerRowFile.getColumnPosition(NAME_COLUMN));
		String oficialDescription = importRowFile.getStringValue(headerRowFile.getColumnPosition(OFICIAL_DESCRIPTION_COLUMN));
		String email = importRowFile.getStringValue(headerRowFile.getColumnPosition(EMAIL_COLUMN));
		String address = importRowFile.getStringValue(headerRowFile.getColumnPosition(ADDRESS_COLUMN));
		String telephone = importRowFile.getStringValue(headerRowFile.getColumnPosition(TELEPHONE_COLUMN));

        Hotel hotel = new Hotel();
        hotel.setUrlAddress(urlAddress);
        hotel.setName(name);
        hotel.setEmail(email);
        hotel.setAddress(address);
        hotel.setTelephone(telephone);
        hotel.setOficialDescription(oficialDescription);
        return (T) hotel;
    }

    public String[] getHeaderColumnsNames() {
        return new String[]{NAME_COLUMN, OFICIAL_DESCRIPTION_COLUMN, URL_ADDRESS_COLUMN};
    }
}
